//设置和进程名称相关的函数

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

#include "global.h"

void InitSetProcTitle() {
	env_mem = new char[env_need_mem];
	memset(env_mem, 0, env_need_mem);

	char* tmp = env_mem;
	for(int i=0; environ[i]; i++) {
		size_t size = strlen(environ[i])+1;
		strcpy(tmp, environ[i]);
		environ[i] = tmp;
		tmp += size;
	}
	return;
}

void SetProcTitle(const char *title) {
	size_t title_len = strlen(title);
	size_t esy_len = argv_need_mem + env_need_mem;

	if(esy_len <= title_len) {
		return;
	}
	os_argv[1] = NULL;
	char *tmp = os_argv[0];
	strcpy(tmp,title);
	tmp += title_len;
	size_t fill_len = esy_len - title_len;
	memset(tmp,0,fill_len);
	return;
}
